﻿using WRJClient.DAL;
using WRJClient.ViewModel;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using WRJClient.Common;

namespace WRJClient.UI.SystemMonitor
{
    /// <summary>
    /// InfoPanel.xaml 的交互逻辑
    /// </summary>
    public partial class InfoPanel : UserControl
    {
        public delegate void SelectedItemChangedHandler(object sender, RoutedPropertyChangedEventArgs<object> e);
        public event SelectedItemChangedHandler SelectedItemChanged;
        private ObservableCollection<TopoTreeNodeItem> _items = new ObservableCollection<TopoTreeNodeItem>();

        public InfoPanel()
        {
            InitializeComponent();
            BuildTree();

            //ControlCenterManager.Instance.OnDataAdded += Instance_OnDataAdded;
            //WorkStationManager.Instance.OnDataAdded += Instance_OnDataAdded;
            //UAVManager.Instance.OnDataAdded += Instance_OnDataAdded;
            MissionManager.Instance.OnDataAdded += Instance_OnDataAdded;
            //AirlineManager.Instance.OnDataAdded += Instance_OnDataAdded;
            InfomationManager.Instance.OnDataAdded += Instance_OnDataAdded;
            //ZoneManager.Instance.OnDataAdded += Instance_OnDataAdded;
            

        }

        private void Instance_OnDataAdded(object sender, DataChangedEventArgs e)
        {
            BuildTree();
        }

        public void BuildTree()
        {
            _items.Clear();

            //#region //指挥中心
            //TopoTreeNodeItem controlcenters = new TopoTreeNodeItem("指挥中心");
            //foreach (var vm in ControlCenterManager.Instance.Datas)
            //{
            //    TopoTreeNodeItem item = new TopoTreeNodeItem(vm);
            //    controlcenters.Children.Add(item);
            //}
            //_items.Add(controlcenters);
            //#endregion

            //#region //工作站
            //TopoTreeNodeItem workstations = new TopoTreeNodeItem("工作站");
            //foreach (var vm in WorkStationManager.Instance.Datas)
            //{
            //    TopoTreeNodeItem item = new TopoTreeNodeItem(vm);
            //    workstations.Children.Add(item);
            //}
            //_items.Add(workstations);
            //#endregion

            //#region //无人机
            //TopoTreeNodeItem uavs = new TopoTreeNodeItem("无人机");
            //foreach (var vm in UAVManager.Instance.Datas)
            //{
            //    TopoTreeNodeItem item = new TopoTreeNodeItem(vm);
            //    uavs.Children.Add(item);
            //}
            //_items.Add(uavs);
            //#endregion

            #region //任务
            TopoTreeNodeItem missions = new TopoTreeNodeItem("任务");
            foreach (var vm in MissionManager.Instance.Datas)
            {
                TopoTreeNodeItem item = new TopoTreeNodeItem(vm);
                missions.Children.Add(item);
            }
            _items.Add(missions);
            #endregion

            //#region //空域
            //TopoTreeNodeItem zones = new TopoTreeNodeItem("空域");
            //foreach (var vm in ZoneManager.Instance.Datas)
            //{
            //    TopoTreeNodeItem item = new TopoTreeNodeItem(vm);
            //    zones.Children.Add(item);
            //}
            //_items.Add(zones);
            //#endregion

            //#region //航线
            //TopoTreeNodeItem airlines = new TopoTreeNodeItem("航线");
            //foreach (var vm in AirlineManager.Instance.Datas)
            //{
            //    TopoTreeNodeItem item = new TopoTreeNodeItem(vm);
            //    airlines.Children.Add(item);
            //}
            //_items.Add(airlines);
            //#endregion

            #region //情报
            TopoTreeNodeItem infomations = new TopoTreeNodeItem("情报");
            foreach (var vm in InfomationManager.Instance.Datas)
            {
                TopoTreeNodeItem item = new TopoTreeNodeItem(vm);
                infomations.Children.Add(item);
            }
            _items.Add(infomations);
            #endregion

            _items.Add(new TopoTreeNodeItem("统计分析"));

            infoTree.ItemsSource = _items;
        }

        private void infoTree_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs<object> e)
        {
            SelectedItemChanged?.Invoke(sender, e);
        }
    }
}
